package com.lagou.edu.repository;

import com.lagou.edu.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 赵虎
 * @date 2021/4/1 12:44 上午
 */
@Repository
public interface OrderRepository extends JpaRepository<Order, Integer> {

    @Modifying
    @Transactional
    @Query(value = "update t_order set order_status = 'paid' where id = ?1 and order_status = 'to_be_paid'", nativeQuery = true)
    int updateOrderPaid(Integer orderId);

    @Modifying
    @Transactional
    @Query(value = "update t_order set order_status = 'cancelled' where id = ?1 and order_status = 'to_be_paid'", nativeQuery = true)
    void updateOrderCancelled(Integer orderId);
}
